﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Collections;

/// <summary>
/// Summary description for Alert
/// </summary>
public class Alert
{
    public Alert()
    {
    }

    public static void sendAlert(int custId, String category, String information, String url)
    {
        SqlConnection conn = DBManager.getSqlConnection();
        conn.Open();
        string sql = "INSERT INTO R_ALERT (category,cust_id,info,url) values(@itemName,@custId,@info,@url)";
            var cmd = new SqlCommand(sql, conn);
            cmd.Parameters.AddWithValue("@custId", custId);
            cmd.Parameters.AddWithValue("@itemName", category);
            information = information +"  [" +Convert.ToString(DateTime.Now)+"] ";
            cmd.Parameters.AddWithValue("@info", information);
            cmd.Parameters.AddWithValue("@url", url);
            cmd.ExecuteNonQuery();
        
        conn.Close();
    }



    public static void confirm(int id)
    {

        string sql = "delete from R_ALERT " +
                       " where alert_id=@itemId";

        SqlConnection conn = DBManager.getSqlConnection();
        SqlCommand cmd = new SqlCommand(sql, conn);
        cmd.Parameters.AddWithValue("@itemId", id);
        conn.Open();
        int row = cmd.ExecuteNonQuery();
        conn.Close();
    }




    public static DataTable getAlerts(int custId)
    {
       return DBManager.GetData("select * from R_ALERT WHERE cust_id='"+custId+"'");
    }
}